package cn.dong.base.handler;

import cn.dong.api.domain.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**aop*/
@ControllerAdvice
@Slf4j
/**
 * 统一处理异常类
 */
public class MyExceptionHandler {

    /**
     * 统一处理全部的异常信息
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public CommonResult<String> error(CustomException e){
        log.error("统一处理的异常：" + e.getMessage());
        e.printStackTrace();
        return CommonResult.error().message(e.getMessage()).code(e.getCode());
    }

}
